﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
namespace GUI
{
    public partial class FormDangNhap : Form
    {
        public FormDangNhap()
        {
            InitializeComponent();
        }

        public static String NV;
        public static String Loai;
        private void FormDangNhap_Load(object sender, EventArgs e)
        {
            
            List<NhanVienDTO> lnv = NhanVienBUS.SelectALLNhanVien();
            this.cbbMaNV.DataSource = lnv;
            cbbMaNV.DisplayMember = "MANV";
            cbbMaNV.ValueMember = "MANV";
            cbbMaNV.SelectedIndex = lnv.Count-1;
            this.txtMatKhau.Text = "123456";
            SS.taikhoan = lnv[0];            
            /*DataTable db = new DataTable();
            db.Columns.Add("Text");
            db.Columns.Add("value");

            foreach (var i in lnv)
            {
                db.Rows.Add(i.MANV+i.TEN,i.MANV);
            }
            cbbMaNV.DataSource = db;
            cbbMaNV.DisplayMember = "Text";
            cbbMaNV.ValueMember = "value";
            cbbMaNV.SelectedIndex = 0;*/
                        
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            String mANV = this.cbbMaNV.Text.Trim();
            String pw = this.txtMatKhau.Text.Trim();
            int kt=0;
            kt = NhanVienBUS.SelectNhanVienByMaNVPASS(mANV, pw);

            if (kt == 0)
            {
                MessageBox.Show("Sai ten nhan vien hoac mat khau!");
            }
            else
            {
                NV = mANV;
                MessageBox.Show("Dang nhap thanh cong!");
                NhanVienDTO nhanvien = NhanVienBUS.SelectNhanVienByMaNV(mANV);
                Loai = nhanvien.LOAINV.Trim();
                SS.taikhoan = nhanvien;
                this.Visible = false;
                Form1 frm = new Form1();
                frm.Show();
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
